package com.huawei.esdk.uc.device.u19.attendee;

import com.huawei.ecs.bin.service.AddAtte;
import com.huawei.ecs.bin.service.AddAtteAck;
import com.huawei.ecs.bin.service.DelAtte;
import com.huawei.ecs.bin.service.DelAtteAck;
import com.huawei.ecs.bin.service.OperateAtte;
import com.huawei.ecs.bin.service.OperateAtteAck;
import com.huawei.ecs.bin.service.SetAtte;
import com.huawei.ecs.bin.service.SetAtteAck;
import com.huawei.ecs.bin.service.SetChairman;
import com.huawei.ecs.bin.service.SetChairmanAck;
import com.huawei.esdk.platform.common.SDKErrorCode;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.uc.device.AbstractU19Capability;
import com.huawei.esdk.uc.device.u19.IAttendeeCapability;
import com.huawei.esdk.uc.device.u19.attendee.convert.AttendeeCapabilityConvert;
import com.huawei.esdk.uc.domain.model.bean.AttendeeInfo;
import com.huawei.esdk.uc.domain.model.u19.Attendee;

public class AttendeeCapabilityImpl extends AbstractU19Capability implements IAttendeeCapability
{
    private AttendeeCapabilityConvert attendeeCapabilityConvert = new AttendeeCapabilityConvert();
    
    private static final AttendeeCapabilityConvert ATTENDEE_CAPABILITY_CONVERT = new AttendeeCapabilityConvert();
    
    public SDKErrorCode operateAttendee(Attendee attendee)
    {
        SDKErrorCode result = new SDKErrorCode();
        OperateAtte atte = ATTENDEE_CAPABILITY_CONVERT.getOperateAttendeeModel2Bin(attendee);
        OperateAtteAck atteAck = getUcU19Provider().sendMsg(atte, attendee.getGwIp(), OperateAtteAck.class);
        result.setErrCode(atteAck.retCode_);
        result.setDescription(atteAck.getCmdCode().name() + " " + atteAck.getCmdCode().value());
        
        return result;
    }
    
    @Override
    public SDKErrorCode modifyAttendeeAuthority(Attendee attendee)
    {
        SDKErrorCode result = new SDKErrorCode();
        SetAtte atte = ATTENDEE_CAPABILITY_CONVERT.getModifyAttendeeAuthority(attendee);
        SetAtteAck atteAck = getUcU19Provider().sendMsg(atte, attendee.getGwIp(), SetAtteAck.class);
        result.setErrCode(atteAck.retCode_);
        result.setDescription(atteAck.getCmdCode().name() + " " + atteAck.getCmdCode().value());
        
        return result;
    }
    
    @Override
    public SDKErrorCode transferChairman(Attendee attendee)
    {
        SDKErrorCode result = new SDKErrorCode();
        SetChairman chairman = ATTENDEE_CAPABILITY_CONVERT.getTransferChairman(attendee);
        SetChairmanAck chairmanAck = getUcU19Provider().sendMsg(chairman, attendee.getGwIp(), SetChairmanAck.class);
        result.setErrCode(chairmanAck.retCode_);
        result.setDescription(chairmanAck.getCmdCode().name() + " " + chairmanAck.getCmdCode().value());
        
        return result;
    }
    
    @Override
    public SDKResult<AttendeeInfo> addAttendee(Attendee attendee)
    {
        SDKResult<AttendeeInfo> sdkResult = new SDKResult<AttendeeInfo>();
        AddAtte addAtte = attendeeCapabilityConvert.getAddAttendeeU19Model2Bin(attendee);
        AddAtteAck response = getUcU19Provider().sendMsg(addAtte, attendee.getGwIp(), AddAtteAck.class);
        sdkResult = attendeeCapabilityConvert.getAddAttendeeU19Bin2Model(response);
        
        return sdkResult;
    }
    
    @Override
    public SDKResult<AttendeeInfo> delAttendee(Attendee attendee)
    {
        SDKResult<AttendeeInfo> sdkResult = new SDKResult<AttendeeInfo>();
        DelAtte delAtte = attendeeCapabilityConvert.getDelAttendeeU19Model2Bin(attendee);
        DelAtteAck response = getUcU19Provider().sendMsg(delAtte, attendee.getGwIp(), DelAtteAck.class);
        sdkResult = attendeeCapabilityConvert.getDelAttendeeU19Bin2Model(response);
        
        return sdkResult;
    }
    
}
